package org.openeccos.excel;

import java.util.Calendar;
import java.util.Map;

import org.apache.poi.hssf.usermodel.HSSFCell;
import org.apache.poi.hssf.usermodel.HSSFCellStyle;
import org.apache.poi.hssf.usermodel.HSSFRow;
import org.apache.poi.hssf.usermodel.HSSFSheet;

/** 
 */
public abstract class XlsAbstract {

	protected Map<String, HSSFCellStyle> styleMap;

	protected HSSFRow createRow(HSSFSheet sheet, int currRow) {
		HSSFRow row = sheet.getRow(currRow);
		if (row == null) {
			row = sheet.createRow(currRow);
		}
		return row;
	}

	protected HSSFCell createCell(HSSFSheet sheet, int currRow, short currCol, String styleStr) {
		HSSFRow row = createRow(sheet, currRow);

		HSSFCell cell = row.createCell(currCol);
		cell.setCellStyle(styleMap.get(styleStr));

		return cell;
	}

	protected HSSFCell createCell(HSSFSheet sheet, int currRow, short currCol, String value, String styleStr) {
		HSSFCell cell = createCell(sheet, currRow, currCol, styleStr);
		cell.setCellValue(value);
		return cell;
	}

	protected HSSFCell createCell(HSSFSheet sheet, int currRow, short currCol, double value, String styleStr) {
		HSSFCell cell = createCell(sheet, currRow, currCol, styleStr);
		cell.setCellValue(value);
		return cell;
	}

	protected HSSFCell createCell(HSSFSheet sheet, int currRow, int currCol, String value, String styleStr) {
		HSSFCell cell = createCell(sheet, currRow, (short) currCol, styleStr);
		cell.setCellValue(value);
		return cell;
	}

	protected HSSFCell createCell(HSSFSheet sheet, int currRow, int currCol, double value, String styleStr) {
		HSSFCell cell = createCell(sheet, currRow, (short) currCol, styleStr);
		cell.setCellValue(value);
		return cell;	
	}
	
	protected HSSFCell createCell(HSSFSheet sheet, int currRow, int currCol, Calendar date) {
		HSSFRow row = createRow(sheet, currRow);
		HSSFCell cell = row.createCell((short)currCol);
		cell.setCellValue(date);
		return cell;	
	}

}